package demo2;

class Animal {
    //初始化，使用代码块
    int age;
    String name;

    static{
        System.out.println("Animal :: static");
    }

    {
        System.out.println("Animal::");
    }

    public Animal(int age, String name) {
        this.age = age;
        this.name = name;
        System.out.println("Animal(age,name)");
    }

    public void eat(){
        System.out.println(name + "正在吃饭");
    }
}

class Dog extends Animal{
    public Dog(int age, String name){
        super(age,name);
        System.out.println("Dog(int age, String name)");
    }

    static{
        System.out.println("Dog :: static");
    }

    {
        System.out.println("Dog :: ");
    }
}

public class Test {
    /// 顺序为:静态代码块执行、实例代码块执行、构造方法执行
    /// 父类静态代码块优先于子类静态代码块执行
    public static void main1(String[] args) {
        Dog dog1 = new Dog(2,"Lucky");
        System.out.println("==================");
        Dog dog2 = new Dog(3,"肯德基");
    }
}
